const router = require('koa-router')()
const Mock = require('mockjs')
const { tabs } = Mock.mock({
  "tabs|2": [{
    "title|+1": ["正在热映", "即将热映"],
    "id": "@id",
    "children|10-20": [{
      "id": "@id",
      "images|4-10": ["@image(120x160, @color, image)"],
      "title": "@ctitle",
      "type|1": ["", "3D|MAX", "2D|MAX"],
      "score": "@float(0, 9, 1, 2)",
      // "names|2-4": ["女演厅", "黄晓明", "都江", "谭卓", "肖战", "李欣", "孟美岐", "强森", "杰森", "胡歌", "刘诗诗", "杨幂", "彭于晏", "刘德华", "周润发", "陈冠希", "周星驰"],
      "names|2-4": [{
        "name|+1": ["女演厅", "黄晓明", "都江", "谭卓", "肖战", "李欣", "孟美岐", "强森", "杰森", "胡歌", "刘诗诗", "杨幂", "彭于晏", "刘德华", "周润发", "陈冠希", "周星驰"]
      }],
      "cinemaCount|100-500": 1,
      "count|1000-5000": 1
    }]
  }]
})
// 列表接口

router.get('/tabs', ctx => {
  ctx.body = {
    code: 200,
    data: tabs
  }
})

router.get('/tabs/detail', ctx => {
  const { id } = ctx.request.query;
  let result = null
  tabs.forEach(v => {
    v.children.forEach(v => {
      if (v.id === id) {
        result = v
      }
    })
  })

  if (result) {
    ctx.body = {
      code: 200,
      data: result
    }
  } else {
    ctx.body = {
      code: 404,
      msg: '未找到该数据'
    }
  }
})

// 详情接口
module.exports = router
